<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>MvcCms -
        <%=ViewData["PageTitle"]%></title>
    <link href="/Content/App_Themes/BackOffice/css/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <style type="text/css">
        label.error
        {
            float: none;
            color: red;
            padding-left: .5em;
            vertical-align: top;
        }
    </style>

    <script type="text/javascript">
        function SelectFile(fileUrl) {
            var opener = window.top.opener;

            var data = {
                fileDate: '',
                fileSize: 456,
                fileUrl: fileUrl,
                selectFunctionData: ''
            }

            opener['CKEDITOR'].tools.callFunction("1", fileUrl, data);
            window.close();
            
        }
        function DeleteImage(imageToDelete, cellnum) {
            $.post(
            "/backofficeajax/deleteimage/0/" + imageToDelete,
            function(data) {
                var objdata = JSON.parse(data);
                if (objdata.error) {
                    alert(objdata.error);
                }
                else {
                    if (objdata.result == "success") {
                        RemoveFileContainer(cellnum);
                    }
                    else {
                        alert("There was a problem removing the image.");
                    }
                }
            },
            "json"
            );
        }

        function RemoveFileContainer(rownum) {
            $("#cell-" + rownum).fadeOut("normal", function() {
                $(this).remove();
            });
        }


    </script>

</head>
<body>
    <div class="contentpage-outerdiv">
        <h2>
            <%=ViewData["PageTitle"]%></h2>
        <span class="field-validation-error">
            <%=ViewData["message"].ToString()%></span>
        <% using (Html.BeginForm("ImageManager", "BackOffice", FormMethod.Post, new { id = "form1", enctype = "multipart/form-data" }))
           {%>
        <div>
            <div>
                Upload Images</div>
            <div>
                <table>
                    <tr>
                        <td>
                            Zip File:
                        </td>
                        <td>
                            <input type="file" id="file1" name="filezip" />
                        </td>
                        <td rowspan="3">
                            <input type="submit" id="Submit1" value="Upload" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Single File:
                        </td>
                        <td>
                            <input type="file" id="File2" name="singlefile" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div style="height: 389px; overflow: scroll">
            <fieldset>
                <legend>
                    <%=Html.Encode(Model._Files.Count().ToString())%>
                    Images Detected</legend>
                <table border="1">
                    <%
                        int i = 0;
                        foreach (var file in Model._Files)
                        {
                            if ((i % 4) == 0)
                            {%>
                                <tr><td>
                          <%}
                            else
                            {%>
                                <td>
                          <%}%>
                          <table id="cell-<%=i %>"><tr>
                        <td>
                            <a href="/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/<%=file.Name%>">
                                <img border="0" alt="<%=Html.Encode(file.Name)%>" src="/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/thumbs/<%=file.Name%>" />
                            </a>
                        </td>
                        <td>
                            <%=Html.Encode(file.LastWriteTime.ToString("d"))%>
                        </td>
                        <td>
                            <a onclick="DeleteImage('<%=file.Name %>', <%=i %>)" href="javascript:void(0)">Del</a>
      
                            <a onclick="SelectFile('/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/<%=file.Name%>')" href="javascript:void(0)">Use</a>
                            
                            <a onclick="SelectFile('/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/thumbs/<%=file.Name%>')" href="javascript:void(0)">Use Thumb</a>
                        </td>    </tr></table>
                          <%
                            if ((i % 2) != 0)
                            {%>
                                </td></tr>
                          <%}
                            else
                            {%>
                                </td>
                          <%}
                            
                            i += 1;
                        } %>
                </table>
            </fieldset>
        </div>
        <%} %>
    </div>
</body>
</html>
